/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 :miv */
/*
//
// BEGIN SONGBIRD GPL
//
// This file is part of the Songbird web player.
//
// Copyright(c) 2005-2008 POTI, Inc.
// http://songbirdnest.com
//
// This file may be licensed under the terms of of the
// GNU General Public License Version 2 (the "GPL").
//
// Software distributed under the License is distributed
// on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
// express or implied. See the GPL for the specific language
// governing rights and limitations.
//
// You should have received a copy of the GPL along with this
// program. If not, go to http://www.gnu.org/licenses/gpl.html
// or write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// END SONGBIRD GPL
//
*/

#ifndef __SB_ALBUMVIEWSCAN_H__
#define __SB_ALBUMVIEWSCAN_H__

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//
// Songbird album view scanner.
//
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------

/**
 * \file  sbAlbumViewScan.h
 * \brief Songbird Album View Scan Component Definitions.
 */

//------------------------------------------------------------------------------
//
// Songbird album view scan component.
//
//------------------------------------------------------------------------------

#include "sbAlbumViewCommon.h"

// Songbird imports.
#include <sbIAlbumViewScan.h>
#include <sbIMediaListView.h>
#include <sbIJobCancelable.h>
#include <sbIJobProgress.h>
#include <sbIJobProgressUI.h>

// Mozilla imports.
#include <nsIArray.h>
#include <nsCOMArray.h>
#include <nsCOMPtr.h>
#include <nsITimer.h>

//------------------------------------------------------------------------------
//
// Songbird album view scan defs.
//
//------------------------------------------------------------------------------

//
// Songbird album view scan component defs.
//

#define SB_ALBUMVIEWSCAN_CLASSNAME "sbAlbumViewScan"
#define SB_ALBUMVIEWSCAN_CID                                                   \
  /* {f2981a97-b34c-415c-bbb9-7e029ef4b83f} */                                 \
{                                                                              \
    0xf2981a97,                                                                \
    0xb34c,                                                                    \
    0x415c,                                                                    \
    { 0xbb, 0xb9, 0x7e, 0x02, 0x9e, 0xf4, 0xb8, 0x3f }                         \
}

//------------------------------------------------------------------------------
//
// Songbird album view scan class.
//
//------------------------------------------------------------------------------

class sbAlbumViewScan : public sbIAlbumViewScan,
                        public sbIJobProgressUI,
                        public sbIJobCancelable,
                        public nsITimerCallback
{
public:
  NS_DECL_ISUPPORTS
  NS_DECL_SBIALBUMVIEWSCAN
  NS_DECL_SBIJOBPROGRESS
  NS_DECL_SBIJOBPROGRESSUI
  NS_DECL_SBIJOBCANCELABLE
  NS_DECL_NSITIMERCALLBACK

  sbAlbumViewScan();
  virtual ~sbAlbumViewScan();

protected:
  // Media List View we are scanning
  nsCOMPtr<sbIMediaListView>                mMediaListView;

  // The library list
  nsCOMPtr<sbIMediaList>                    mLibraryList;

  // Timers for doing our work
  nsCOMPtr<nsITimer>                        mIntervalTimer;
  PRInt32                                   mIntervalTimerValue;

  // Job Progress Information
  PRUint16                                  mStatus;
  PRUint32                                  mTotalItemCount;
  PRUint32                                  mCurrentItemCount;

  nsString                                  mCurrentAlbumName;
  nsCOMArray<sbIJobProgressListener>        mListeners;
  PRBool                                    mNextAlbum;

  // Creates a properly sorted view from the media list for parsing
  nsresult CreateSortedView(sbIMediaList* aMediaList);

  // Find all albums in the list
  nsresult ProcessAlbums();
  
  // Find the next album in the list
  nsresult ProcessNextAlbum();

  // Update the progress to the listeners
  nsresult UpdateProgress();
};

#endif // __SB_ALBUMSERVICE_H__
